<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.Map" %>
<%@page import="java.util.List" %>
<%@page import="java.util.Iterator" %>
<%@page import="java.math.BigDecimal" %>
<%@page import="java.text.DecimalFormat" %>
<div id="login">
    <% if((Boolean)session.getAttribute("isLogged")) { %>
    <span class="boto" id="nomUser">&nbsp;<%=session.getAttribute("nom") %> <%=session.getAttribute("cognoms") %>&nbsp;</span>
    <% } else {%>
        <div class="boto" id="botoLI">Login</div>
        <input type=password" value="Password" id="pass" tabindex="20" />
        <input type="text" value="Correu Electronic" id="user" tabindex="21" />
    <% } %>
</div>

<div id="minimenu">
    <div class="boto" id="carret">Carret:
        &nbsp;<span style="font-weight: bold;"><%=session.getAttribute("totalCarret") %>&euro;</span>,
        &nbsp;<span style="font-weight: bold;"><%=session.getAttribute("itemsCarret") %></span> productes
    </div>
    <% if(!(Boolean)session.getAttribute("isLogged")) { %>
    <div class="boto" id="reg">Registrar-se</div>
    <% } %>
</div>

<div id="menuOp">
    <div class="boto2" id="pref">Preferencies</div>
    <div class="boto2" id="sortir">Sortir</div>
</div>

<div id="menuCarret">
    <div class="prods">
        <% List<Map<String, Object>> carret = (List<Map<String, Object>>) session.getAttribute("llistatCarret");
        if ( carret == null || carret.isEmpty() || (Integer)session.getAttribute("itemsCarret") <= 0) {
        %>
            <span class="noProd">No hi ha productes</span>
    </div>
        <% } else { %>
            <div>
                <span class="uni"></span>
                <span class="nomItem">Nom Producte</span>
                <span class="euro">Subtotal</span>
                <span class="euro">&euro;&frasl;u</span>
                <span class="elim"></span>
            </div>

           <%
           Iterator<Map<String, Object>> it = carret.iterator();
           Map<String, Object> dada;
            while(it.hasNext()) {
                dada = it.next();
                DecimalFormat formatter = new DecimalFormat("####0.00");
           %>
            <div>
                <span class="uni"><%=dada.get("quantitat") %></span>
                <span class="nomItem"><%=dada.get("nom") %></span>
                <span class="elim" value="<%=dada.get("id_prod") %>">X</span>
                <span class="euro"><%=formatter.format(((BigDecimal)dada.get("preu")).floatValue()*((BigDecimal)dada.get("quantitat")).intValue()) %>&euro;</span>
                <span class="euro"><%=dada.get("preu") %>&euro;</span>
            </div>
        <%  } %>
    </div>
    <% if((Boolean)session.getAttribute("isLogged")) { %>
    <div class="boto" value="7">Confirmar Compra</div>
    <% } %>
    <div class="boto" value="6">Buidar Carret</div>
        <% }%>
</div>